package com.fansmac.sc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RequestMapping("/rest")
@RestController
public class RestTemplateController {

    Logger LOGGER = LoggerFactory.getLogger(RestTemplateController.class);

    @Autowired
    RestTemplate restTemplate;


    @RequestMapping(method = RequestMethod.GET)
    public String consumerEchoMethod(String content) {
        String msg = restTemplate.getForObject("http://my-provider/test?content=" + content, String.class);
        LOGGER.info("returnMsg:" + msg + ",content:" + content);
        return msg;

    }

    @RequestMapping(value = "user", method = RequestMethod.GET)
    public String consumerEchoMethodAA(String content) {
        String msg = restTemplate.getForObject("http://my-provider/users/2" + content, String.class);
        LOGGER.info("returnMsg:" + msg + ", content:" + content);
        return msg;

    }

    @RequestMapping(value = "user", method = RequestMethod.POST)
    public String consumerEchoMethodA2(String content) {
        String msg = restTemplate.getForObject("http://my-provider/users/1" + content, String.class);
        LOGGER.info("returnMsg:" + msg + ", content:" + content);
        return msg;

    }


}
